/*
 *  SystemParam.cpp
 *  Milovo03epsilon03
 *
 *  Created by luca on 04/08/06.
 *  Copyright 2006 __MyCompanyName__. All rights reserved.
 *
 */

#include "SystemParam.h"

SystemParams::SystemParams()
{
	NumGeneticGenerations = 40;
	NumGeneticRecipesForInitPopulation = 40;
	MaxLifeRecipes = 15;
	MaxLifeArtifacts = 15;
	SeedRandomValue = 98765;
	ActivityDeadLevel = 1;
	QuantityCeilStartRange = 10;
	QuantityCeilEndRange = 10;
	MinNameArtifactAllowed = 1;
	MaxNameArtifactAllowed = 1000000;
	SaveDatabaseFreq = 10;
	UseGenerativePotential = -1;
	LambdaActivity = 0.01;
	CostRecipes = 0.05;
	ActivitySlowKinetic = 0.01;
	ProbGAMutation = 0.05;
	ProbGAInitPopulation = 0.7;
	XsigmaMin = 0;
	XsigmaMax = 100000;
	YsigmaMin = 0;
	YsigmaMax = 100000;
	EpsilonIfVoteZero = 0.1;
	AlphaVote = 1;
	BetaHeterogeneity = 1;
	GammaAlignedDirectedness = 1;
	AgentSelectionMode = 2;
	ScaffoldingMaxLevel = 0;
	UseEvents = 0;
	BornNewAgents = -0.2;
	GrowCoefficient = -0.001;
	InitPopulationType = 1;
}

void SystemParams::LoadSystemParam(string strPath)
{
	string tmpFileInitnetParam(strPath);
	ifstream in(tmpFileInitnetParam.c_str());
	
	string tmpSingleParam;
	while(getline(in, tmpSingleParam))
	{
		Mil_Int tmpEqualPos;
		if(tmpSingleParam.find("#"))
		{
			tmpEqualPos = tmpSingleParam.find("=");
			string tmpNameSingleParam(tmpSingleParam, 0, tmpEqualPos);
			string tmpValueSingleParam(tmpSingleParam, tmpEqualPos + 1, tmpSingleParam.size());
			if(tmpNameSingleParam == "AgentSelectionMode") AgentSelectionMode = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "MinNameArtifactAllowed") MinNameArtifactAllowed = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "MaxNameArtifactAllowed") MaxNameArtifactAllowed = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "QuantityCeilStartRange") QuantityCeilStartRange = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "QuantityCeilEndRange") QuantityCeilEndRange = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "EpsilonIfVoteZero") EpsilonIfVoteZero = atof(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "NumGeneticGenerations") NumGeneticGenerations = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "NumGeneticRecipesForInitPopulation") NumGeneticRecipesForInitPopulation = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "ProbGAInitPopulation") ProbGAInitPopulation = atof(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "ProbGAMutation") ProbGAMutation = atof(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "LambdaActivity") LambdaActivity = atof(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "CostRecipes") CostRecipes = atof(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "MaxLifeRecipes") MaxLifeRecipes = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "MaxLifeArtifacts") MaxLifeArtifacts = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "SeedRandomValue") SeedRandomValue = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "ActivitySlowKinetic") ActivitySlowKinetic = atof(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "ActivityDeadLevel") ActivityDeadLevel = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "XsigmaMin") XsigmaMin = atof(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "XsigmaMax") XsigmaMax = atof(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "YsigmaMin") YsigmaMin = atof(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "YsigmaMax") YsigmaMax = atof(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "SaveDatabaseFreq") SaveDatabaseFreq = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "UseGenerativePotential") UseGenerativePotential = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "AlphaVote") AlphaVote = atof(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "BetaHeterogeneity") BetaHeterogeneity = atof(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "GammaAlignedDirectedness") GammaAlignedDirectedness = atof(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "ScaffoldingMaxLevel") ScaffoldingMaxLevel = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "UseEvents") UseEvents = atol(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "BornNewAgents") BornNewAgents = atof(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "GrowCoefficient") GrowCoefficient = atof(tmpValueSingleParam.c_str());
			if(tmpNameSingleParam == "InitPopulationType") InitPopulationType = atol(tmpValueSingleParam.c_str());
		}
	}
	
	cout << "InitPopulationType: " << InitPopulationType << endl;
}

SystemParams::~SystemParams()
{
}

void SystemParams::PrintSystemParam()
{
	cout << "-- BEGIN PRINT SYSTEM PARAMETERS -- " << endl;
	cout << "NumGeneticGenerations: " << NumGeneticGenerations << endl;
	cout << "MaxLifeRecipes: " << MaxLifeRecipes << endl;
	cout << "MaxLifeArtifacts: " << MaxLifeArtifacts << endl;
	cout << "NumGeneticRecipesForInitPopulation: " << NumGeneticRecipesForInitPopulation << endl;
	cout << "SeedRandomValue: " << SeedRandomValue << endl;
	cout << "ActivityDeadLevel: " << ActivityDeadLevel << endl;
	cout << "QuantityCeilStartRange: " << QuantityCeilStartRange << endl;
	cout << "QuantityCeilEndRange: " << QuantityCeilEndRange << endl;
	cout << "MinNameArtifactAllowed: " << MinNameArtifactAllowed << endl;
	cout << "MaxNameArtifactAllowed: " << MaxNameArtifactAllowed << endl;
	cout << "SaveDatabaseFreq: " << SaveDatabaseFreq << endl;
	cout << "UseGenerativePotential: " << UseGenerativePotential << endl;
	cout << "LambdaActivity: " << LambdaActivity << endl;
	cout << "CostRecipes: " << CostRecipes << endl;
	cout << "ActivitySlowKinetic: " << ActivitySlowKinetic << endl;
	cout << "ProbGAMutation: " << ProbGAMutation << endl;
	cout << "ProbGAInitPopulation: " << ProbGAInitPopulation << endl;
	cout << "XsigmaMin: " << XsigmaMin << endl;
	cout << "XsigmaMax: " << XsigmaMax << endl;
	cout << "YsigmaMin: " << YsigmaMin << endl;
	cout << "YsigmaMax: " << YsigmaMax << endl;
	cout << "EpsilonIfVoteZero: " << EpsilonIfVoteZero << endl;
	cout << "AlphaVote: " << AlphaVote << endl;
	cout << "BetaHeterogeneity: " << BetaHeterogeneity << endl;
	cout << "GammaAlignedDirectedness: " << GammaAlignedDirectedness << endl;
	cout << "AgentSelectionMode: " << AgentSelectionMode << endl;
	cout << "BornNewAgents: " << BornNewAgents << endl;
	cout << "GrowCoefficient: " << GrowCoefficient << endl;
	cout << "-- END PRINT SYSTEM PARAMETERS -- " << endl;
}

